package com.example.demo.service.impl;

import com.example.demo.dao.Executive;
import com.example.demo.mapper.ExecutiveInfoMapper;
import com.example.demo.service.ExecutiveService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExecutiveServiceImpl implements ExecutiveService {

    private final ExecutiveInfoMapper executiveInfoMapper;

    public ExecutiveServiceImpl(ExecutiveInfoMapper executiveInfoMapper) {
        this.executiveInfoMapper = executiveInfoMapper;
    }

    @Override
    public Boolean addExecutiveInfo(Executive executive) {
        try {
            executiveInfoMapper.save(executive);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }

    @Override
    public Boolean updateExecutiveInfo(Executive executive) {
        //执行mapper的更新语句
        try {
            executiveInfoMapper.save(executive);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }

    @Override
    public Executive selectExecutiveInfoByECode(String code) {

        return executiveInfoMapper.findByExecutiveCode(code);
    }

    @Override
    public List<Executive> selectAllExecutiveInfoByCompanyCode(String code) {
        return executiveInfoMapper.findAllByCompanyCode(code);
    }

    @Override
    public Integer deleteExecutiveByECode(String code) {


        return executiveInfoMapper.deleteByExecutiveCode(code);
    }
}
